package model

import (
	"context"
	"fmt"
	"gorm.io/gorm"
	"time"
	"unlimited-comments/global"
)

type Like struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:点赞id;primaryKey;not null;"  form:"id" json:"id"` // 点赞id
	UserId    int32          `gorm:"column:user_id;type:int;comment:用户id;not null;"  form:"user_id" json:"user_id"`      // 用户id
	VideoId   int32          `gorm:"column:video_id;type:int;comment:视频id;not null;"  form:"video_id" json:"video_id"`   // 视频id
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);"  form:"created_at" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);"  form:"updated_at" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;"  form:"deleted_at" json:"deleted_at"`
}

func (l *Like) TableName() string {
	return "like"
}

func (l *Like) AddLike() error {

	err := global.DB.Create(&l).Error
	global.RDB.Set(context.Background(), fmt.Sprintf("comment:%d", l.Id), l, 0)
	return err
}
